package com.mioto.ld.communication.websocket.resolver;

import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import com.mioto.ld.communication.websocket.model.SendCmdEnum;
import com.mioto.ld.communication.websocket.model.WsRecMessage;
import com.mioto.ld.communication.websocket.util.MessageSendUtil;
import com.mioto.ld.communication.websocket.util.WsChannelUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @author mioto-qinxj
 * @date 2024/5/16
 * @desc
 */
@Slf4j
public class WsAuthMessageResolver implements WsMessageResolver{

    @Override
    public void resolve(ChannelHandlerContext channelHandlerContext, WsRecMessage message) {
        // 将客户端唯一标识作为自定义属性加入到channel中，方便随时channel中获取
        WsChannelUtil.getAttr(channelHandlerContext).setIfAbsent(message.getClientId());
        //缓存连接通道
        WsChannelUtil.put(channelHandlerContext);
        MessageSendUtil.send(channelHandlerContext.channel(), SendCmdEnum.AUTH_SUCCESS);
    }
}
